﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;

namespace Portal.Workflow.Model
{
    public class WorkFlowRecordCls
    {
        public string BatchId="";
        public string Id;
        public string WorkFlowDefId;
        public string WorkflowDefName;
        public string EmployeeId;
        public string RecordId;
        public string RecordNote;
        public string Subject;
        public DateTime ActionDate;
        public string ProcessId;
        public string ViewParam;
        public string ComeFrom;
        public string ComeFromName;
        public string ComeFromOffice="";
        public string PreviewUrl;
        public string DelayNote="";
        public string LinkId;
        public string XmlData = "";
        public string fromOfficeCode = "";
        public string toOfficeCode = "";
        public string PriorityId = "";
        public string PriorityText = "";
        public string ExtraInfo = "";
        public string ExtraData = "";
        public int Sent = 0;

        public string GetXml()
        {
            DataSet ds = new DataSet();
            ds.Tables.Add("Info");
            ds.Tables["Info"].Columns.Add("BatchId");
            ds.Tables["Info"].Columns.Add("Id");
            ds.Tables["Info"].Columns.Add("WorkFlowDefId");
            ds.Tables["Info"].Columns.Add("WorkflowDefName");
            ds.Tables["Info"].Columns.Add("EmployeeId");
            ds.Tables["Info"].Columns.Add("RecordId");
            ds.Tables["Info"].Columns.Add("RecordNote");
            ds.Tables["Info"].Columns.Add("Subject");
            ds.Tables["Info"].Columns.Add("ActionDate");
            ds.Tables["Info"].Columns.Add("ProcessId");
            ds.Tables["Info"].Columns.Add("ViewParam");
            ds.Tables["Info"].Columns.Add("ComeFrom");
            ds.Tables["Info"].Columns.Add("ComeFromOffice");
            ds.Tables["Info"].Columns.Add("PreviewUrl");
            ds.Tables["Info"].Columns.Add("DelayNote");
            ds.Tables["Info"].Columns.Add("LinkId");
            ds.Tables["Info"].Columns.Add("XmlData");
            ds.Tables["Info"].Columns.Add("fromOfficeCode");
            ds.Tables["Info"].Columns.Add("toOfficeCode");
            ds.Tables["Info"].Columns.Add("PriorityId");
            ds.Tables["Info"].Columns.Add("PriorityText");
            ds.Tables["Info"].Columns.Add("Sent");
            ds.Tables["Info"].Columns.Add("ExtraInfo");
            ds.Tables["Info"].Columns.Add("ExtraData");

            ds.Tables["Info"].Rows.Add(new object[]{
                BatchId,
                Id,
                WorkFlowDefId,
                WorkflowDefName,
                EmployeeId,
                RecordId,
                RecordNote,
                Subject,
                ActionDate,
                ProcessId,
                ViewParam,
                ComeFrom,
                ComeFromName,
                ComeFromOffice,
                PreviewUrl,
                DelayNote,
                LinkId,
                XmlData,
                fromOfficeCode,
                toOfficeCode,
                PriorityId,
                PriorityText,
                Sent = 0,
                ExtraInfo,
                ExtraData
            });
            return ds.GetXml();
        }

        public void Parse(string Xml)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(new StringReader(Xml));
            BatchId=ds.Tables[0].Rows[0]["BatchId"].ToString();
            Id=ds.Tables[0].Rows[0]["Id"].ToString();
            WorkFlowDefId=ds.Tables[0].Rows[0]["WorkFlowDefId"].ToString();
            WorkflowDefName=ds.Tables[0].Rows[0]["WorkflowDefName"].ToString();
            EmployeeId=ds.Tables[0].Rows[0]["EmployeeId"].ToString();
            RecordId=ds.Tables[0].Rows[0]["RecordId"].ToString();
            RecordNote=ds.Tables[0].Rows[0]["RecordNote"].ToString();
            Subject=ds.Tables[0].Rows[0]["Subject"].ToString();
            ActionDate=DateTime.Parse(ds.Tables[0].Rows[0]["ActionDate"].ToString());
            ProcessId=ds.Tables[0].Rows[0]["ProcessId"].ToString();
            ViewParam=ds.Tables[0].Rows[0]["ViewParam"].ToString();
            ComeFrom=ds.Tables[0].Rows[0]["ComeFrom"].ToString();
            ComeFromName=ds.Tables[0].Rows[0]["ComeFromName"].ToString();
            ComeFromOffice=ds.Tables[0].Rows[0]["ComeFromOffice"].ToString();
            PreviewUrl=ds.Tables[0].Rows[0]["PreviewUrl"].ToString();
            DelayNote=ds.Tables[0].Rows[0]["DelayNote"].ToString();
            LinkId=ds.Tables[0].Rows[0]["LinkId"].ToString();
            XmlData=ds.Tables[0].Rows[0]["XmlData"].ToString();
            fromOfficeCode=ds.Tables[0].Rows[0]["fromOfficeCode"].ToString();
            toOfficeCode=ds.Tables[0].Rows[0]["toOfficeCode"].ToString();
            PriorityId=ds.Tables[0].Rows[0]["PriorityId"].ToString();
            PriorityText=ds.Tables[0].Rows[0]["PriorityText"].ToString();
            Sent = int.Parse(ds.Tables[0].Rows[0]["Sent"].ToString());
            ExtraInfo = ds.Tables[0].Rows[0]["ExtraInfo"].ToString();
            ExtraData = ds.Tables[0].Rows[0]["ExtraData"].ToString();
        }
    }
}
